﻿using System;
using System.Collections.Generic;
using System.Text;
using FaceCat;
using System.Drawing;
using System.Diagnostics;

namespace FaceCat
{
    /// <summary>
    /// 我的颜色
    /// </summary>
    public class MyColor
    {
        public static String m_systemFont = "";

        public static void setSystemFont(String value)
        {
            m_systemFont = value;
        }

        public static String getSystemFont()
        {
            if (m_systemFont.Length == 0)
            {
                m_systemFont = "Segoe UI";
            }
            return m_systemFont;
        }

        /// <summary>
        /// 上次的样式
        /// </summary>
        public int m_lastStyle = -1;

        /// <summary>
        /// 风格
        /// </summary>
        public static int m_style = 0;

        /// <summary>
        /// 设置样式
        /// </summary>
        /// <param name="style"></param>
        public static void setStyle(int style)
        {
            m_style = style;
        }

        /// <summary>
        /// 我的颜色
        /// </summary>
        public HashMap<long, long> m_userColors = new HashMap<long, long>();

        /// <summary>
        /// 创建颜色
        /// </summary>
        public virtual void createColors()
        {
            m_userColors.Clear();
            if (m_style == 1)
            {
                m_userColors[FCColor.Back] = FCColor.rgb(255, 255, 255); //1
                m_userColors[FCColor.Border] = FCColor.rgb(200, 200, 200); //1
                m_userColors[FCColor.Text] = FCColor.rgb(0, 0, 0); //1
                m_userColors[FCColor.DisabledBack] = FCColor.rgba(0, 0, 0, 25); //1
                m_userColors[FCColor.DisabledText] = 3289650;
                m_userColors[FCColor.Hovered] = FCColor.rgba(43, 138, 195, 150);
                m_userColors[FCColor.Pushed] = FCColor.rgba(43, 138, 195, 100);
            }
            else
            {
                m_userColors[FCColor.Back] = FCColor.rgb(19, 21, 26);
                m_userColors[FCColor.Border] = FCColor.rgb(50, 50, 50);
                m_userColors[FCColor.Text] = FCColor.rgb(255, 255, 255);
                m_userColors[FCColor.DisabledBack] = FCColor.rgba(255, 255, 255, 25);
                m_userColors[FCColor.DisabledText] = 3289650;
                m_userColors[FCColor.Hovered] = FCColor.rgba(43, 138, 195, 150);
                m_userColors[FCColor.Pushed] = FCColor.rgba(43, 138, 195, 100);
            }
        }

        public static long m_hoverdColor = FCColor.None;

        /// <summary>
        /// 获取黑色风格的颜色
        /// </summary>
        /// <param name="color">颜色</param>
        /// <returns>新的颜色</returns>
        public virtual long getUserColor(long color)
        {
            if (m_lastStyle != m_style)
            {
                m_lastStyle = m_style;
                createColors();
            }
            long tColor = 0;
            if (m_userColors.TryGetValue(color, out tColor))
            {
                return tColor;
            }
            return color;
        }
    }

    /// <summary>
    /// 绘图类
    /// </summary>
    public class FCDraw
    {
        /// <summary>
        /// 绘制文字
        /// </summary>
        /// <param name="paint">绘图对象</param>
        /// <param name="text">文字</param>
        /// <param name="dwPenColor">颜色</param>
        /// <param name="font">字体</param>
        /// <param name="x">横坐标</param>
        /// <param name="y">纵坐标</param>
        public static FCSize drawText(FCPaint paint, String text, long dwPenColor, FCFont font, int x, int y)
        {
            FCSize tSize = paint.textSize(text, font, -1);
            FCRect tRect = new FCRect(x, y, x + tSize.cx, y + tSize.cy);
            paint.drawText(text, dwPenColor, font, tRect, -1);
            return tSize;
        }

        /// <summary>
        /// 绘制有下划线的数字
        /// </summary>
        /// <param name="paint">绘图对象</param>
        /// <param name="value">值</param>
        /// <param name="digit">保留小数位数</param>
        /// <param name="font">字体</param>
        /// <param name="fontColor">文字颜色</param>
        /// <param name="zeroAsEmpty">0是否为空</param>
        /// <param name="x">横坐标</param>
        /// <param name="y">纵坐标</param>
        /// <returns>绘制的横坐标</returns>
        public static int drawUnderLineNum(FCPaint paint, double value, int digit, FCFont font, long fontColor, bool zeroAsEmpty, int x, int y)
        {
            if (zeroAsEmpty && value == 0)
            {
                String text = "-";
                FCSize size = paint.textSize(text, font, -1);
                FCDraw.drawText(paint, text, fontColor, font, x, y);
                return size.cx;
            }
            else
            {
                String[] nbs = FCTran.getValueByDigit(value, digit).Split(new String[] { "." }, StringSplitOptions.RemoveEmptyEntries);
                if (nbs.Length == 1)
                {
                    FCSize size = paint.textSize(nbs[0], font, -1);
                    FCDraw.drawText(paint, nbs[0], fontColor, font, x, y);
                    return size.cx;
                }
                else
                {
                    FCSize decimalSize = paint.textSize(nbs[0], font, -1);
                    FCSize size = paint.textSize(nbs[1], font, -1);
                    FCDraw.drawText(paint, nbs[0], fontColor, font, x, y);
                    FCDraw.drawText(paint, nbs[1], fontColor, font, x
                        + decimalSize.cx, y);
                    paint.drawLine(fontColor, 1, 0, x
                        + decimalSize.cx, y + decimalSize.cy,
                        x + decimalSize.cx + size.cx, y + decimalSize.cy);
                    return decimalSize.cx + size.cx;
                }
            }
        }
    }
}
